package com.mcxx.modules.system.service.impl;

import com.mcxx.modules.system.service.SalvationTaskExportService;
import com.mcxx.modules.system.dao.read.TaskExportReadDao;
import com.mcxx.modules.system.entity.TaskExportEntity;
import com.mcxx.modules.system.service.read.TaskExportReadService;
import com.mcxx.modules.system.service.write.TaskExportWriteService;
import com.yinhai.ta404.core.restservice.requestbean.PageParam;
import com.yinhai.ta404.core.restservice.resultbean.Page;
import com.yinhai.ta404.core.security.vo.UserAccountVo;
import com.yinhai.ta404.core.service.BaseService;
import com.yinhai.ta404.core.transaction.annotation.TaTransactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
@TaTransactional
public class SalvationTaskExportServiceImpl extends BaseService implements SalvationTaskExportService {

    @Autowired
    private TaskExportReadDao taskExportReadDao;
    @Autowired
    private TaskExportWriteService taskExportWriteService;

    @Override
    public Page findPage(PageParam pageParam, UserAccountVo userAccountVo) {
        String usreId = userAccountVo.getUserId();
        taskExportReadDao.beginPager(pageParam);
        List<TaskExportEntity> list = taskExportReadDao.queryListByUser(usreId);
        return taskExportReadDao.endPager(list);
    }


    public TaskExportEntity getById(String id){
        return taskExportReadDao.getById(id);
    }

    @Override
    public int delete(String id) {
        TaskExportEntity taskExport = new TaskExportEntity();
        taskExport.setId(id);
        return taskExportWriteService.delete(taskExport);
    }

    @Override
    public int update(String id) {
        TaskExportEntity entity = new TaskExportEntity();
        entity.setId(id);
        entity.setFinishTime(new Date());
        return taskExportWriteService.updateIgnoreNull(entity);
    }
}
